function sum(str) {
  let arr = [];// [1,2,4]
  let sum = 0;
  let s = 0;
  for (let i = 0; i < str.length; i++) {
    if (str[i] === '0') s += 1;
    if (str[i] !== '0' || str[i + 1] === undefined) {
      if (s > 0) {
        arr.push(s);
        s = 0
      }
    }
  }
  arr.forEach(item => {
    for (let i = 1; i <= item; i++) {
      sum += i
    }
  });
  return sum
}

let res = sum('0100100001220013,fsafdsj0000');
console.log(res);
